package com.self.av;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class GridOverlayView extends View {
    private Paint gridPaint;

    public GridOverlayView(Context context) {
        super(context);
        init();
    }

    public GridOverlayView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public GridOverlayView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        gridPaint = new Paint();
        gridPaint.setColor(Color.WHITE);
        gridPaint.setStrokeWidth(2);
        gridPaint.setAlpha(128); // 设置透明度
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int width = getWidth();
        int height = getHeight();

        // 绘制垂直网格线
        for (int x = 0; x < width; x += 50) {
            canvas.drawLine(x, 0, x, height, gridPaint);
        }

        // 绘制水平网格线
        for (int y = 0; y < height; y += 50) {
            canvas.drawLine(0, y, width, y, gridPaint);
        }
    }
}